<!--
 * @FilePath     : /study_code/jquery/api-fn-extend.html
 * @Description  : $.fn.extend(object) 自定义一个简易插件
 * @Date         : 2025-04-16 15:27:38
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-04-17 11:30:47
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <!-- <link rel="stylesheet" href="" /> -->
  </head>
  <body>
    <button id="btn1">使所有复选框选中</button>
    <button id="btn2">使所有复选框 取消选中</button>
    <hr />

    <label for="hoby1">
      <input id="hoby1" type="checkbox" />
      写作
    </label>
    <label for="hoby2">
      <input id="hoby2" type="checkbox" checked />
      钢琴
    </label>
    <label for="hoby3">
      <input id="hoby3" type="checkbox" />
      跳舞
    </label>
    <label for="hoby4">
      <input id="hoby4" type="checkbox" checked />
      书法
    </label>

    <script src="/jquery/dist/jquery.min.js"></script>
    <script>
      jQuery.fn.extend({
        check: function () {
          return this.each(function () {
            this.checked = true
          })
        },
        uncheck: function () {
          return this.each(function () {
            this.checked = false
          })
        },
      })

      $('#btn1').on('click', function () {
        $('input[type=checkbox]').check()
      })

      $('#btn2').on('click', function () {
        $('input[type=checkbox]').uncheck()
      })
    </script>
  </body>
</html>
